package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:  Lemon
 * @Description:  分类相关接口
 * @Date:    2024/12/27 13:50
 */

@Controller
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * @Author Lemon
     * @Description 修改分类
     * @Date 2024/12/27 16:02
     * @Param [categoryDTO]
     * @Return com.sky.result.Result
     */
    @PutMapping
    @ResponseBody
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    /**
     * @Author Lemon
     * @Description 分页查询
     * @Date 2025-01-06 15:16
     * @Param [categoryPageQueryDTO]
     * @Return com.sky.result.Result
     */
    @GetMapping("/page")
    @ResponseBody
    public Result pageCategory(CategoryPageQueryDTO categoryPageQueryDTO) {
        Object data = categoryService.pageCategory(categoryPageQueryDTO);
        return Result.success(data);
    }

    /**
     * @Author Lemon
     * @Description 启用、禁用分类
     * @Date 2025-01-06 15:43
     * @Param [status, id]
     * @Return com.sky.result.Result
     */
    @PostMapping("/status/{status}")
    @ResponseBody
    public Result updateStatus(@PathVariable String status ,String id) {
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * @Author Lemon
     * @Description 新增分类
     * @Date 2025-01-06 16:29
     * @Param [category]
     * @Return com.sky.result.Result
     */
    @PostMapping
    @ResponseBody
    public Result addCategory(@RequestBody Category category) {
        categoryService.addCategory(category);
        return Result.success();
    }

    /**
     * @Author Lemon
     * @Description 根据id删除分类
     * @Date 2025-01-06 16:38
     * @Param [id]
     * @Return com.sky.result.Result
     */
    @DeleteMapping
    @ResponseBody
    public Result deleteCategory(String id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }
}
